package com.health.controller;

import com.health.common.Result;
import com.health.common.ResultCode;

/**
 * @Description
 * @Author konglz
 * @Data 2023/3/22 18:56
 */
public class BaseController {

    public Result success() {
        return Result.success(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
    }

    public Result error() {
        return Result.error(ResultCode.ERROR.getCode(), ResultCode.ERROR.getMessage());
    }

    public Result rowResult(Integer row) {
        return row > 0 ? success() : error();
    }

    public Result result(Boolean flag) {
        return flag ? success() : error();
    }

    public Result dataResult(Object data) {
        return Result.success(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    public Result booleanResult(boolean flag) {
        return flag == true ? Result.success(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), flag) : Result.error(ResultCode.ERROR.getCode(), ResultCode.ERROR.getMessage(), flag);
    }
}
